package com.pointtown.vcrss.activity;

import com.pointtown.vcrss.R;
import com.pointtown.vcrss.database.Entry;
import com.pointtown.vcrss.database.RSSTabeleDAO;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class DetailActivity extends Activity {
	
	private static final String TAG = "DetailActivity";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detail);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		Bundle extras = getIntent().getExtras();
		long id = extras.getLong("id");
		Log.v(TAG, id + "");
		
		TextView tvTitle = (TextView)findViewById(R.id.text_title);
		TextView tvDetail = (TextView)findViewById(R.id.text_detail);
		
		// selectById
		RSSTabeleDAO dao = new RSSTabeleDAO(this);
		Entry entry = null;
		try {
			entry = dao.getEntryById("" + id);
		} catch (Exception e) {
			Toast.makeText(this, "スタッフに連絡してください", Toast.LENGTH_LONG).show();
			tvTitle.setText("Error:DB not access");
			tvDetail.setText("Mail:vegecolle.yu@gmail.com");
			return;
		}
		
		tvTitle.setText(entry.getTitle());
		tvDetail.setText(entry.getDescription());
	}
}
